<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装防抖函数(键盘抬起事件)</title>
</head>
<body>
    <input type="text" id="input">
    <script>
        let inputEle = document.getElementById('input')

        function debounce(callback, wait = 500){
            let timer
            return function(...arg){
                if(timer){
                    clearTimeout(timer)
                }timer = setTimeout(() => {
                    callback.apply(this, arguments)
                }, wait)

            }
        }
        inputEle.addEventListener('keyup',debounce(function(event){
            console.log(this, event);
            
        }))
    </script>
</body>
</html>